{extend name="public/base"}

{block name="main"}
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 用户中心 <span class="c-gray en">&gt;</span> 会员列表<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="Hui-article">
    <article class="cl pd-20">
        <form action="{:url('save_menu')}" method="post" class="form form-horizontal" id="wx_menu_form">
            <div id="tab-system" class="HuiTab">
                <div class="tabBar cl"><span>菜单设置</span><span>文本回复</span><span>图文回复</span></div>
                <div class="tabCon">
                    <button class="btn btn-success size-MINI sync-menu" type="button"> 同步微信菜单 </button>
                    <table class="table table-border table-bordered table-hover table-bg table-sort">
                        <thead>
                        <tr class="text-c">
                            <th width="2%"><i class="fa fa-star"></i></th>
                            <th width="25%">菜单名称</th>
                            <th width="10%">菜单类型</th>
                            <th>菜单内容</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist name="data" id="vo"}
                        <tr data-index="{$vo.index}" data-two-index="{$vo.two_index}">
                            <td><i class="Hui-iconfont">&#xe630;</i></td>
                            <td>
                                <input type="text" class="form-control" name="name[{$vo.index}][{$vo.two_index}]" value="{$vo.name}" style=" height: 23px; font-size: 8px; float: left; {gt name='vo.two_index' value='0'} margin-left: 2em; {/gt}">
                                <p style="float: left; margin-left: 5px; margin-bottom: 0;">
                                    {eq name='vo.two_index' value='0'}
                                    <button class="btn btn-default radius size-MINI add_menu"><i class="Hui-iconfont">&#xe600;</i> 添加</button>
                                    {/eq}
                                    <button class="btn btn-default radius size-MINI del_menu"><i class="Hui-iconfont">&#xe6e2;</i> 删除</button>
                                </p>
                            </td>
                            <td>
                                <div class="form-group" style=" margin-bottom: 0">
                                    <select class="form-control m-b" name="account[{$vo.index}][{$vo.two_index}]" style="height: 23px; padding: 0 12px; font-size: 8px; margin: 0; ">
                                        <option value="view" {eq name="vo.account" value="view"} selected {/eq}>链接</option>
                                        <option value="click" {eq name="vo.account" value="click"} selected {/eq}>触发关键字</option>
                                        <option value="scancode_push" {eq name="vo.account" value="scancode_push"} selected {/eq}>扫码</option>
                                        <option value="scancode_waitmsg" {eq name="vo.account" value="scancode_waitmsg"} selected {/eq}> 扫码（等待信息）</option>
                                        <option value="pic_sysphoto" {eq name="vo.account" value="pic_sysphoto"} selected {/eq}>系统拍照发图</option>
                                        <option value="pic_photo_or_album" {eq name="vo.account" value="pic_photo_or_album"} selected {/eq}>拍照或者相册发图</option>
                                        <option value="pic_weixin" {eq name="vo.account" value="pic_weixin"} selected {/eq}>微信相册发图</option>
                                        <option value="location_select" {eq name="vo.account" value="location_select"} selected {/eq}>地理位置</option>
                                    </select>
                                </div>
                            </td>
                            <td>
                                <input type="text" class="form-control" name="value[{$vo.index}][{$vo.two_index}]" value="{$vo.value}" style=" height: 23px; font-size: 8px; width: 100%;">
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                <div class="tabCon"> </div>
                <div class="tabCon"> </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9">
                    <button class="btn btn-primary btn-xs add_menu add_level_one"><i class="Hui-iconfont">&#xe600;</i> 添加一级分类</button>
                    <button onClick="article_save_submit();" class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
                    <button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
                </div>
            </div>
        </form>
    </article>
</div>
{/block}

{block name="javascript"}
<script>
    $(function () {
        $(document).on('click', '.add_menu', function () {
            var level = 0, index = 0, two_index = 0;
            var _this = $(this);
            if (_this.hasClass('add_level_one')) {
                level = 1;
                index = $("tbody tr:last").data('index') + 1;
            } else {
                index = _this.parents('tr').data('index');
                var last_two_index = _this.parents('tr').next().data('two-index');
                if (last_two_index > 0) {
                    two_index = last_two_index + 1;
                } else {
                    two_index = 1;
                }
            }
            var html = '<tr data-index="'+ index +'" data-two-index="'+ two_index +'">' +
                    '<td><i class="fa fa-star"></i></td>' +
                    '<td>';
            if(level == 1) {
                html += '<input type="text" class="form-control" name="name['+index+']['+two_index+']" value="" style=" height: 23px; font-size: 8px; float: left; ">';
            } else {
                html += '<input type="text" class="form-control" name="name['+index+']['+two_index+']"  value="" style=" height: 23px; font-size: 8px; float: left; margin-left: 2em">';
            }
            html += '<p style="float: left; margin-left: 5px; margin-bottom: 0;">';
            if(level == 1) {
                html += '<button class="btn btn-white btn-xs add_menu"><i class="fa fa-plus"></i> 添加</button>';
            }
            html += '<button class="btn btn-white btn-xs del_menu"><i class="fa fa-trash"></i> 删除</button>' +
                    '</p>' +
                    '</td>' +
                    '<td>' +
                    '<div class="form-group" style=" margin-bottom: 0">' +

                    '<select class="form-control m-b" name="account['+index+']['+two_index+']" style="height: 23px; padding: 0 12px; font-size: 8px; margin: 0;">' +

                    '<option selected="" value="view">链接</option>' +
                    '<option value="click">触发关键字</option>' +
                    '<option value="scancode_push">扫码</option>' +
                    '<option value="scancode_waitmsg"> 扫码（等待信息）</option>' +
                    '<option value="pic_sysphoto">系统拍照发图</option>' +
                    '<option value="pic_photo_or_album">拍照或者相册发图</option>' +
                    '<option value="pic_weixin">微信相册发图</option>' +
                    '<option value="location_select">地理位置</option>' +
                    '</select>' +
                    '</div>' +
                    '</td>' +
                    '<td>' +

                    '<input type="text" class="form-control" name="value['+index+']['+two_index+']" value="" style=" height: 23px; font-size: 8px; width: 100%;">' +
                    '</td>' +
                    '</tr>';
            if(level == 1)
                $('tbody').append(html);
            else
                _this.parents('tr').after(html);
        });

        $(document).on('click', '.del_menu', function () {
            var _this = $(this);
            _this.parents('tr').remove();
        });

        $("#wx_menu_form").submit(function (e) {
            e.preventDefault();
            var _this = $(this);
            console.log(_this.serialize());
            $.ajax({
                type : _this.attr('method'),
                url : _this.attr('action'),
                data : _this.serialize(),
                dataType : 'json',
                success : function (msg) {
                    if (msg.code == 200) {
                        layer.msg(msg.msg, {icon: 6,time:1000});
                    } else {
                        layer.msg(msg.msg, {icon: 5,time:1000});
                    }
                }
            });
        });

        // 同步微信菜单
        $(".sync-menu").click(function () {
            $.get("{:url('sync_menu')}", function (msg) {
                if (msg.code == 200) {
                    layer.msg(msg.msg, {icon: 6,time:1000});
                } else {
                    layer.msg(msg.msg, {icon: 5,time:1000});
                }
            });
        });
    });
</script>
{/block}